package com.miao.model
{
	import org.puremvc.as3.multicore.patterns.proxy.Proxy;
	
	public class ConfigProxy extends Proxy
	{
		
		public static const NAME:String = "ConfigProxy";
		
		public function ConfigProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		override public function setData(data:Object):void{
			super.setData(data);
			
		}
		
		public function get xml():XML{
			return data as XML;
		}
		
		public function getRefererUrl(url:String):String{
			var xmlL:XMLList = xml..chapter.children().(@src==url);
			if(xmlL.length()>0){
				var _xml:XML = xmlL[0];
				if(_xml.hasOwnProperty("@referer")) return _xml.@referer;
				else if(_xml.parent().hasOwnProperty("@referer")) return _xml.parent().@referer;
				else if(_xml.parent().parent().hasOwnProperty("@referer")) return _xml.parent().parent().@referer;
			}
			
			return null;
		}
		
		public function getNextXml(url:String):XML{
			var xmlL:XMLList = xml..chapter.children();
			
			for(var i:int=xmlL.length()-1;i>=0;i--){
				var _xml:XML = xmlL[i];
				if(_xml.@src==url){
					var nextIndex:int = i+1;
					if(nextIndex<xmlL.length()){
						return xmlL[nextIndex];
					}
				}
			}
			
			return null;
		}
	}
}